package com.qk.management.controller;

import com.qk.common.Result;
import com.qk.domain.user.UserDO;
import com.qk.dto.user.UserDto;
import com.qk.entity.User;
import com.qk.management.aop.ann.LogAnn;
import com.qk.management.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
 *  @author SHCJ
 *  @created 2025/10/6 12:48
 *  @description
 */
@RestController
@RequestMapping("/users")
public class UserController {
    @Autowired
    private UserService userService;
//    分页查询
    @GetMapping
    public Result page(UserDto userDto){

        return Result.success(userService.page(userDto));
    }

//    新增
    @LogAnn
    @PostMapping
    public Result add(@RequestBody UserDO userDO){
        userService.addUser(userDO);
        return Result.success();
    }

//    批量删除

    @LogAnn
    @DeleteMapping("/{ids}")
    public Result deleteByIds(@PathVariable List<Integer> ids){
        userService.deleteByIds(ids);
        return Result.success();
    }
//    根据id查询
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        return Result.success(userService.findById(id));
    }

//    修改用户
    @LogAnn
    @PutMapping
    public Result update(@RequestBody User user){
        userService.update(user);
        return Result.success();
    }

//    查询所有用户
    @GetMapping("/list")
    public Result selectAll(){
        return Result.success(userService.selectAll());
    }

//    根据角色查询用户
    @GetMapping("/role/{roleLabel}")
    public Result selectByRole(@PathVariable String roleLabel){
        return Result.success(userService.selectByRole(roleLabel));
    }

//    根据部门查询
    @GetMapping("/dept/{deptId}")
    public Result selectByDept(@PathVariable Integer deptId){
        return Result.success(userService.selectByDept(deptId));
    }
}
